﻿using AuthCenter.Api.Read.Application.Command.RoleMenu;
using AuthCenter.Api.Read.Application.Output;
using AuthCenter.Common.Common;
using AuthCenter.Domain;
using AuthCenter.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace AuthCenter.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleMenuController : ControllerBase
    {
        private readonly IMediator mediator;
        public RoleMenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<RoleModel>>> GetRole([FromQuery] GetRoleCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取角色菜单
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<RoleMenuOutput>>> GetMenuRoleId([FromQuery] GetMenuRoleIdCommand request) 
        {
            var userId=HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var userName = HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
            var roleName= HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var customerValue = HttpContext.User.FindFirst("CustomClaimType")?.Value;
            var key=HttpContext.User.FindFirst("key")?.Value;
            return mediator.Send(request);
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Task<ApiResult<UserLoginOutput>> Login([FromQuery] LoginCommand request) 
        {

            string idStr = "230624200409152329".GetBirthCarId();
            return mediator.Send(request);
        }
        /// <summary>
        /// 根虎角色ID查询菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<UserRoleMenuOutput>>> GetUserRoleMenuShow([FromQuery]GetUserRoleMenuCommand request) 
        {
           
            return mediator.Send(request);
        }
    }
}
